<!doctype html>
<html dir="ltr" xml:lang="pt" lang="pt">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="language" content="pt-br" />

    <%=
        sprintf('<title>%s</title>', CHtml::encode($this->pageTitle));
        $baseUrl = Yii::app()->request->baseUrl;
        $user = Yii::app()->user;
        date_default_timezone_set('America/Sao_Paulo');
    %>
</head>

<body>
    <div id="header">
        <div class="row">
            <div id="logo">
                <%= sprintf('<img alt="" src="%s/images/logo.png" class="logo" />', $baseUrl); %>
            </div>
            <div id="identity">
                <%= sprintf(
                    '<span class="name">Olá, %s</span>
                     <span id="time">%s</span>', $user->isGuest ? 'Visitante' : $user->getFirstName(), date('H:i:s'));
                %>
            </div>
            <div id="analog">
                <canvas id="clock"></canvas>
            </div>
        </div>
    </div>
    <%
        if(!$user->isGuest):
            $isAdmin = $user->isAdmin();
            $isOperator = $user->isOperator();
    %>
        <div id="main-menu">
            <div class="row">
                <ul>
                    <li>
                        <%= sprintf('<a href="%s/%s" tabindex="-1">Ver matriz</a>', $baseUrl, 'atividade'); %>
                    </li>
                    <li>
                        <%= sprintf('<a href="%s/%s/%s" class="%s" tabindex="-1">Cadastrar atividade</a>', $baseUrl, 'atividade', 'create', $isOperator ? '' : 'none'); %>
                    </li>
                    <li>
                        <%= sprintf('<a href="%s/%s" tabindex="-1">Listar usuários</a>', $baseUrl, 'usuario'); %>
                    </li>
                    <li>
                        <%= sprintf('<a href="%s/%s/%s" class="%s" tabindex="-1">Cadastrar usuário</a>', $baseUrl, 'usuario', 'create', $isAdmin ?  '' : 'none'); %>
                    </li>
                    <li>
                        <%= sprintf('<a href="%s/%s" tabindex="-1">Listar instalações</a>', $baseUrl, 'instalacao'); %>
                    </li>
                    <li>
                        <%= sprintf('<a href="%s/%s/%s" class="%s" tabindex="-1">Cadastrar instalação</a>', $baseUrl, 'instalacao', 'create', $isAdmin ? '' : 'none'); %>
                    </li>
                    <li>
                        <%= sprintf('<a href="%s/%s" tabindex="-1">Ver estatísticas</a>', $baseUrl, 'estatistica'); %>
                    </li>
                    <li>
                        <%= sprintf('<a href="%s/%s/%s" tabindex="-1">Sair</a>', $baseUrl, 'site', 'logout'); %>
                    </li>
                </ul>
                <div class="clear"></div>
            </div>
        </div>
    <% endif; %>

    <%= $content; %>

    <div class="clear"></div>

    <div id="footer">
        Copyright &copy; <%= date('Y'); %> PFC - Matriz de sincronização - Breno e Girardi<br/>
        Todos Direitos Reservados.
        <%= Yii::powered(); %>
    </div><!-- footer -->

    <div id="msg"></div>
</body>

<%
    $clientScript = Yii::app()->getClientScript();
	$clientScript->registerCoreScript('jquery');
	$clientScript->registerCssFile($baseUrl . "/css/core.css");
	$clientScript->registerCssFile($baseUrl . "/css/form.css");
    $clientScript->registerScriptFile($baseUrl . "/js/coolclock.js");
    $clientScript->registerScriptFile($baseUrl . "/js/tipsy.js");
    $clientScript->registerScript('main', "
        // Code for clock
        var second =  " . date('s') . ",
            minute =  " . date('i') . ",
            hour   =  " . date('H') . ",
            today  = '" . date('Y/m/d') . "';

        count_setup();

        function count_setup() {
            setTimeout(function() { increase_count() }, 1000);
        }

        function increase_count() {
            count_setup();
            second = (parseInt(second) + 1)%60;
            minute = (second == 0) ? (parseInt(minute) + 1)%60 : parseInt(minute);
            hour = (minute == 0 && second == 0) ? (parseInt(hour) + 1)%24 : parseInt(hour);

            change_timer();

            if(second == 0 && $('#atividade-grid').length > 0)
                updateGridColor();

            if(hour == 0 && minute == 0 && second == 0) //refresh the page
                location.reload();
        }

        function change_timer() {
            $('#time').html(to2Digits(hour) + ':' + to2Digits(minute) + ':' + to2Digits(second));
        }

        function to2Digits(a) {
            return (parseInt(a) > 9) ? a : '0' + a;
        }

        // Code for showing messages
        function showMessage(msg, isSuccess) {
            $('#msg').html(msg)
            .css('left', 0.5 * ($(document).width() - $('#msg').outerWidth()))
            .addClass( isSuccess ? 'success' : 'error')
            .css('visibility', 'visible');

            setTimeout(
                function() {
                    $('#msg').html('').removeAttr('style').removeClass();
                }, 3000);
        }

        // Code for active (highlight) item on main-menu
        var page = window.location.href.toString().split(window.location.host)[1];
        $('#main-menu a[href=\'' + page + '\']').addClass('active');

        // Code for Tooltips Tipsy
        $('a[rel=tipsy], .grid-view td.button-column a').tipsy({fade: true, gravity: 's', opacity: 1});
    ");
%>
</html>